package com.bls.cate.ui.activity.home;


import android.annotation.SuppressLint;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentTransaction;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.widget.FrameLayout;

import com.blankj.utilcode.util.ToastUtils;
import com.bls.cate.R;
import com.bls.cate.adapter.HomeBottomBarAdapter;
import com.bls.cate.bean.HomeBean;
import com.bls.cate.mvp.MVPBaseActivity;
import com.bls.cate.ui.fragment.alllist.AllListFragment;
import com.bls.cate.ui.fragment.flyleaf.FlyleafFragment;
import com.bls.cate.ui.fragment.me.MeFragment;

import java.util.ArrayList;

import butterknife.BindView;
import butterknife.ButterKnife;


/**
 * MVPPlugin
 * 邮箱 784787081@qq.com
 */

public class HomeActivity extends MVPBaseActivity<HomeContract.View, HomePresenter> implements HomeContract.View, HomeBottomBarAdapter.OnBottomBarClickListener {
    @BindView(R.id.rv_bottom_bar)
    RecyclerView rvBottomBar;
    @BindView(R.id.fl_content)
    FrameLayout flContent;

    private HomeBottomBarAdapter homeBottomBarAdapter;
    private int bottomBarOldClickPosition = -1;     //底部导航栏旧的点击位置

    @Override
    protected void initParams() {
        homeBottomBarAdapter = new HomeBottomBarAdapter(mPresenter.getBottomBarBean());
    }

    @Override
    protected int initLayoutId() {
        return R.layout.activity_home;
    }

    @Override
    protected void initFvb() {
        ButterKnife.bind(this);
    }

    @Override
    protected void initView() {
        mPresenter.switchFragment(0, bottomBarOldClickPosition, getSupportFragmentManager(), mPresenter.getFragments());
        rvBottomBar.setLayoutManager(new GridLayoutManager(getContext(), 3));
        rvBottomBar.setAdapter(homeBottomBarAdapter);
    }

    @Override
    protected void initListener() {
        homeBottomBarAdapter.setOnBottomBarClickListener(this);
    }

    @Override
    public void onBottomBarClick(int position) {
        ToastUtils.showShort(String.valueOf(position));
        mPresenter.switchFragment(position, bottomBarOldClickPosition, getSupportFragmentManager(), mPresenter.getFragments());
    }

    @Override
    public void setNewBottomBarOldClickPosition(int index) {
        bottomBarOldClickPosition = index;
    }
}
